package com.tianji.learning.controller;

import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.domain.vo.LearningPlanVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author zhongweiwei
 * @since 2023-05-24
 */
@RestController
@RequestMapping("/lessons")
@RequiredArgsConstructor
public class LearningLessonController {
    private final ILearningLessonService lessonService;

    @GetMapping("page")
    @ApiOperation("分页查询我的课程")
    public PageDTO<LearningLessonVO> queryMyLessons(PageQuery query) {
        return lessonService.queryMyLessons(query);
    }

    @GetMapping("now")
    @ApiOperation("查询我正在学习的课程")
    public LearningLessonVO queryMyCurrentLesson() {
        return lessonService.queryMyCurrentLesson();
    }

    @GetMapping("{courseId}")
    @ApiOperation("查询指定课程信息")
    public LearningLessonVO queryLessonByCourseId(@ApiParam(value = "课程id", example = "1") @PathVariable("courseId") Long courseId) {
        return lessonService.queryLessonByCourseId(courseId);
    }

    @DeleteMapping("{courseId}")
    @ApiOperation("删除指定的课程")
    public void deleteCourseFromLesson(@ApiParam(value = "课程id", example = "1") @PathVariable("courseId") Long courseId) {
        lessonService.deleteCourseFromLesson(null, courseId);
    }

    @GetMapping("{courseId}/count")
    @ApiOperation("统计课程学习人数")
    public Integer countLearningLessonByCourse(@ApiParam(value = "课程id", example = "1") @RequestParam(value = "courseId", required = false) Long courseId) {
        return lessonService.countLearningLessonByCourse(courseId);
    }

    @GetMapping("{courseId}/valid")
    @ApiOperation("校验当前课程是否已经报名")
    public Long isLessonValid(@ApiParam(value = "课程id", example = "1") @PathVariable("courseId") Long courseId) {
        return lessonService.isLessonValid(courseId);
    }

    @PostMapping("/plans")
    @ApiOperation("创建学习计划")
    public void addLearningPlan(@RequestBody LearningPlanDTO plan) {
        lessonService.addLearningPlan(plan);
    }

    @GetMapping("plans")
    @ApiOperation("查询学习计划列表")
    @ApiParam(name = "query", value = "查询参数")
    public LearningPlanPageVO queryLearningPlan(PageQuery query) {
        return lessonService.queryLearningPlan(query);
    }

}
